package com.todod.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.todod.dto.ApprovalCommentsDto;
import com.todod.entity.ResultData;
import com.todod.mapper.ApprovalCommentsMapper;
import com.todod.model.User;
import com.todod.service.ApprovalCommentsService;
import com.todod.service.IUserService;

/**
 * @author lql
 * @date 2020年12月25日
 */
@RestController
@RequestMapping("/approvalComments")
public class ApprovalCommentsController extends BaseManageController {

	@Autowired
	public ApprovalCommentsService approvalCommentsService;
	@Autowired
	public ApprovalCommentsMapper approvalCommentsMapper;
	@Autowired
	private IUserService iUserService;

	/**
	 * 
	 * @param companyId
	 * @param _userId
	 * @param request
	 * @param queryApprovalComments
	 * @return
	 */
	@RequestMapping("/getList")
	public ResultData getList(@RequestAttribute Long _userId) {

		List<ApprovalCommentsDto> list = approvalCommentsMapper.getList(_userId);
		for (ApprovalCommentsDto record : list) {
			User user = iUserService.getById(record.getCreateuserId());

			record.setCreateuserName(user.getNickName());
		}
		return ResultData.success("ok", list);
	}

	/**
	 * 
	 * @param _userId
	 * @param reqApprovalComments
	 * @return
	 */
	@PostMapping("/approval")
	public ResultData saveData(@RequestAttribute Long _userId, Long otherId, String comments, String approvalStatus,
			String flag) {

		approvalCommentsService.saveData(_userId, otherId, comments, approvalStatus, flag);
		return ResultData.success();
	}

	/**
	 * 
	 * @param code
	 * @return
	 */
	@GetMapping("/getInfo")
	public ResultData getInfo(Long code) {
		if (code == null) {
			return ResultData.error(ResultData.PARAM_ERROR_CODE, "参数错误");
		}
		return ResultData.success("ok", approvalCommentsService.getInfo(code));
	}

}
